clear all;
close all;

A=imread('cameraman.tif');
figure, imshow(A);
[x, y] = ginput(2);
B1 = A(fix(y(1))+[1:8],fix(x(1))+[1:8]);
B2 = A(fix(y(2))+[1:8],fix(x(2))+[1:8]);

B1f = dct2(B1);
B2f = dct2(B2);
Q=[16 11 10 16 24 40 51 61;
   12 12 14 19 26 58 60 55;
   14 13 16 24 40 57 69 56;
   14 17 22 29 51 87 80 62;
   18 22 37 56 68 109 103 77;
   24 35 55 64 81 104 113 92;
   49 64 78 87 103 121 120 101;
   72 92 95 98 112 100 103 99];

B1fq = fix(B1f./Q);
B2fq = fix(B2f./Q);

B1fqr = B1fq.*Q;
B1fr = idct2(B1fqr);

B2fqr = B2fq.*Q;
B2fr = idct2(B2fqr);

subplot(2,1,1),image(B1),colormap(gray(256)), axis('square'), 
subplot(2,1,2),image(B1fr),colormap(gray(256)), axis('square');